<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title></title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
  <div id="app">
    <h1>Hello Vue!</h1>
    <div>
      {{ message }}
    </div>

    <span v-bind:title="message">
      鼠标悬停几秒钟查看此处动态绑定的提示信息！
    </span>

    <p v-if="seen">现在你看到我了</p>
    <button v-on:click="seen=false">隐藏</button>
    <button v-on:click="seen=true">显示</button>

    <ol>
      <li v-for="todo in todos">
        {{ todo.text }}
      </li>
    </ol>
    <p>{{ message }}</p>
    <button v-on:click="reverseMessage">反转消息</button>
    <input v-model="message">

    <ol>
      <todo-item></todo-item>
    </ol>

    <ol>
      <todo-item2
        v-for="item in groceryList"
        v-bind:todo="item"
        v-bind:key="item.id"
      ></todo-item2>
    </ol>
<a href="生命周期.html">下一章：生命周期</a>
  </div>
</body>

</html>
<script>
  // 定义名为 todo-item 的新组件
Vue.component('todo-item', {
  template: '<li>这是个待办项</li>'
})

Vue.component('todo-item2', {
  props: ['todo'],
  template: '<li>{{ todo.text }}</li>'
})

  var app = new Vue({
    el: '#app',
    data: {
      message: 'Hello Vue!',
      seen: true,
      todos: [
        { text: '学习 JavaScript' },
        { text: '学习 Vue' },
        { text: '整个牛项目' }
      ],
      groceryList: [
      { id: 0, text: '蔬菜' },
      { id: 1, text: '奶酪' },
      { id: 2, text: '随便其它什么人吃的东西' }
    ]
    },
    methods: {
      reverseMessage: function () {
        this.message = this.message.split('').reverse().join('')
      }
    }
  })
</script>